#include "buffer.h"

Buffer::Buffer(WINDOW *window, int line, int *linelimit)
{
	int i = 0;
	int o_line, o_column;
	
	int offset = 0;
	int nread = 0;
	getyx(window, o_line, o_column);
	this->window = window;
	this->line = line;
	this->buffer = new char[line * COLS];
	
	for (; i < line; i++)
	{
		wmove(window, i, 0);
		nread = winnstr(this->window, this->buffer + offset, linelimit[i]);
		offset += nread;
		buffer[offset++] = '\n';
	}
	this->size = offset;
	wmove(window, o_line, o_column);
}

Buffer::~Buffer()
{
	if (this->buffer)
		delete[] this->buffer;
}

const char *Buffer::getContent()
{
	return this->buffer;
}

int Buffer::getSize() const
{
	return this->size;
}
